package com.dit.util;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.vaadin.server.VaadinServlet;

public class SpringContextHelper {

	private ApplicationContext context;
	private static SpringContextHelper instance;

	public static SpringContextHelper Instance() {
		if (instance == null) {
			instance = new SpringContextHelper(VaadinServlet.getCurrent()
					.getServletContext());
		}
		return instance;

	}

	public SpringContextHelper(ServletContext servletContext) {
		context = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);
	}

	public Object getBean(final String beanRef) {
		return context.getBean(beanRef);
	}
}